package com.joyance.test_servlet.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class TestHttpSession extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HttpSession================");
        HttpSession session = req.getSession();
        // getCreationTime
        System.out.println("session.getCreationTime()=" + session.getCreationTime());
        // getId()
        System.out.println("session.getId()=" + session.getId());
        // getLastAccessedTime
        System.out.println("session.getLastAccessedTime()=" + session.getLastAccessedTime());
        // getMaxInactiveInterval
        System.out.println("session.getMaxInactiveInterval()=" + session.getMaxInactiveInterval());
        // getValue
        System.out.println("session.getValue(\"name\")=" + session.getValue("name"));
        // getValueNames
        System.out.print("session.getValueNames[");
        for (String name : session.getValueNames()) {
            System.out.print(" " + name + " ");
        }
        System.out.print("]\n");
        // invalidate
        // session.invalidate();
        // session.setAttribute("name", "123");
        // System.out.println("invalidate() session.getValue(\"name\")=" + session.getAttribute("name"));
        // isNew
        System.out.println(session.isNew());
    }
}
